package classic150;

/**
 * <h3>leetcode</h3>
 *
 * @author BigFaceCat
 * @date 2023/12/1 19:58
 * @description <p>leetcode45-跳跃游戏2-数组-中等题</p>
 */
public class No45 {
    public static void main(String[] args) {
        int[] nums = {1, 2};
        System.out.println(jump(nums));
    }

    public static int jump(int[] nums) {

        int count = 1;
        int max1 = 0;
        int max2 = nums[0];
        int len = max2;
        int temp = nums[max1] + max1;

        if (nums.length == 1){
            return 0;
        }

        while (len < nums.length - 1) {

            for (int i = max1; i <= max2; i++) {
                if (nums[i] + i > temp) {
                    len = nums[i] + i;
                    temp = len;
                }
            }

            max1 = max2;
            max2 = len;

            count++;
        }
        return count;
    }

}